package com.ruoyi.web.controller.mdm;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mdm.domain.SkuMasterSub;
import com.ruoyi.mdm.service.ISkuMasterSubService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * sku子Controller
 *
 * @author shiseido
 * @date 2025-03-01
 */
@RestController
@RequestMapping("/mdm/skuMasterSub")
public class SkuMasterSubController extends BaseController {
    @Autowired
    private ISkuMasterSubService skuMasterSubService;

    /**
     * 查询sku子列表
     */
    @ApiOperation("查询sku子列表")
    @PreAuthorize("@ss.hasPermi('mdm:skuMasterSub:list')")
    @GetMapping("/list")
    public TableDataInfo list(SkuMasterSub skuMasterSub) {
        startPage();
        List<SkuMasterSub> list = skuMasterSubService.selectSkuMasterSubList(skuMasterSub);
        return getDataTable(list);
    }

    /**
     * 导出sku子列表
     */
    @ApiOperation("导出sku子列表")
    @PreAuthorize("@ss.hasPermi('mdm:skuMasterSub:export')")
    @Log(title = "sku管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SkuMasterSub skuMasterSub) {
        List<SkuMasterSub> list = skuMasterSubService.selectSkuMasterSubList(skuMasterSub);
        ExcelUtil<SkuMasterSub> util = new ExcelUtil<SkuMasterSub>(SkuMasterSub.class);
        util.exportExcel(response, list, "sku子数据");
    }

    /**
     * 获取sku子详细信息
     */
    @ApiOperation("获取sku子详细信息")
    @PreAuthorize("@ss.hasPermi('mdm:skuMasterSub:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(skuMasterSubService.selectSkuMasterSubById(id));
    }

    /**
     * 新增sku子
     */
    @ApiOperation("新增sku子")
    @PreAuthorize("@ss.hasPermi('mdm:skuMasterSub:add')")
    @Log(title = "sku管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SkuMasterSub skuMasterSub) {
        return toAjax(skuMasterSubService.insertSkuMasterSub(skuMasterSub));
    }

    /**
     * 修改sku子
     */
    @ApiOperation("修改sku子")
    @PreAuthorize("@ss.hasPermi('mdm:skuMasterSub:edit')")
    @Log(title = "sku管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SkuMasterSub skuMasterSub) {
        return toAjax(skuMasterSubService.updateSkuMasterSub(skuMasterSub));
    }

    /**
     * 删除sku子
     */
    @ApiOperation("删除sku子")
    @PreAuthorize("@ss.hasPermi('mdm:skuMasterSub:remove')")
    @Log(title = "sku管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(skuMasterSubService.deleteSkuMasterSubByIds(ids));
    }
}
